﻿<extend name="Public:office" />
<block name="title"><title>情报中心</title></block>
<block name="header_styles">
    <style type="text/css">
        .main-wrapper .container {
            background-color: #ffffff;
        }

        .operation {
            width: 250px;
            text-align: right;
        }
    </style>
</block>
<block name="main">
    <div class="tabs-wrapper">
        <ul class="nav nav-tabs">
            <li class="active"><a href="javascript:void(0);">情报中心</a></li>
        </ul>
        <div class="tab-content">
            <div class="tab-pane active" style="min-height: 600px;">
                <div class="qc">
                    <div>
                        <span class="album-title">最新情报</span>
                        <a href="javascript:void(0);" class="smallbtn btn-default pull-right read-all">设置所有为已读</a>
                    </div>
                    <empty name="list">
                        <div class="alert alert-warning">暂无最新情报</div>
                    </empty>
                    <table class="table table-hover" id="tbLatest">
                        <volist name="list" id="vo">
                            <tr data-info="{$vo.id}">
                                <if condition="$vo['ctime'] lt 1450003584">
                                    <td>{$vo.content}</td>
                                    <td class="operation">
                                        <a href="javascript:void(0);" data-url="">查看</a>&nbsp;|&nbsp;{$vo.ctime|date="Y-m-d H:i",###}
                                    </td>
                                    <else />
                                    {$vo.content}
                                </if>
                            </tr>
                        </volist>
                    </table>
                </div>
                <div class="history-main">
                    <div>
                        <span class="album-title">历史情报</span>
                        <a href="javascript:void(0);" class="smallbtn btn-default pull-right clearLog">清空已读情报</a>
                    </div>
                    <empty name="listold">
                        <div class="alert alert-warning">暂无历史情报</div>
                    </empty>
                    <table class="table table-hover">
                        <volist name="listold" id="vo">
                            <tr>
                                <if condition="$vo['ctime'] lt 1450003584">
                                    <td>{$vo.content}</td>
                                    <else />
                                    {$vo.content}
                                </if>
                                <td class="operation">
                                    <a href="javascript:void(0);" class="delInfo" data-id="{$vo.id|default=0}">删除</a>&nbsp;|&nbsp;{$vo.ctime|date="Y-m-d H:i",###}
                                </td>
                            </tr>
                        </volist>
                    </table>
                </div>
            </div>
        </div>
    </div>
</block>
<block name="footer_scripts">
    <script type="text/javascript">
        require(["jquery", "modules/message"], function ($, boroshare) {
            $(".table td").on("click", "a[data-url]", function () {
                var self = $(this);
                var url = self.data("url");
                var infoID = self.closest("tr").data("info");
                if (!infoID) {
                    window.location = url;
                    return false;
                }
                dealinfo(infoID, url);
                return false;
            });

            //设置所有最新情报为已读
            $(".read-all").on("click", function () {
                if ($("#tbLatest tr").length <= 0) {
                    return false;
                }
                var url = "{:U('/Team/readallog_ajax')}";
                $.post(url, {}, function (data) {
                    var vdata = eval(data);
                    if (vdata.success == 1) {
                        window.location.reload();
                    }
                    else {
                        boroshare.alert({ content: vdata.msg });
                    }
                }, 'json');
                return false;
            });

            //删除情报
            $(".delInfo").on("click", function () {
                var dataId = $(this).data("id");
                var url = "{:U('Team/delinfo_ajax')}";
                $.post(url, { 'info': dataId }, function (data) {
                    var vdata = eval(data);
                    if (vdata.success == 1) {
                        window.location.reload();
                    }
                    else {
                        alert(vdata.msg);
                    }
                    return false;
                }, 'json');
            });

            $(".acceptInvite").on("click", function () {
                var pid = $(this).data("pid");
                var jid = $(this).data("jid");
                var rid = $(this).data("rid");
                var sid = $(this).data("sid");
                var log = $(this).parent().parent().data("info");
                acceptInvite(log, pid, jid, rid, sid);
            });

            function acceptInvite(log, prj, job, r, s) {
                var url = "{:U('Team/acceptInvite_ajax')}";
                $.post(url, { 'prj': prj, 'job': job, 'r': r, 's': s }, function (data) {
                    var vdata = eval(data);
                    boroshare.alert({ content: vdata.msg, sure:function(){dealinfo(log);} });
                    return false;
                }, 'json');
            }

            //清空已读情报
            $(".clearLog").on("click", function clearLog() {
                var url = "{:U('Team/clearlogview_ajax')}";
                $.post(url, {}, function (data) {
                    var vdata = eval(data);
                    if (vdata.success == 1) {
                        window.location.reload();
                    }
                    else {
                        alert(vdata.msg);
                    }
                    return false;
                }, 'json');
            });
            
            //设置情报已读
            function dealinfo(infoID){
                var url = arguments[1]?arguments[1]:'';
                var apiurl = "{:U('Team/dealinfo_ajax')}";
                $.post(apiurl, { 'infoID': infoID }, function (data) {
                    var vdata = eval(data);
                    if (vdata.success == 1) {
                        if (url != '') {
                            window.location = url;
                        }
                        else {
                            window.location.reload();
                        }
                    }
                    else {
                        boroshare.alert({ content: vdata.msg });
                    }
                }, 'json');
            }
        });
    </script>
</block>
